#ifndef __GE_REGISTRY_H__
#define __GE_REGISTRY_H__

#include "GE_Base.h"
namespace Syp
{
///A UniqueRegistry is a class which is used to keep track of a particular type of data. Similar entries are not allowed.
template <class T>
class UniqueRegistry
{
public:
	virtual ~UniqueRegistry()
	{
		///Derived class has to call this. Reason for not calling in base class is because not all registries might want to remove all entries upon deletion of registry.
		//removeAllEntries();
	}
///Adds an entry
///@ Defines the name of the entry. All entries are unique by name.
///@ Pointer to the entry
	void addEntry(const String& name,T* t)
	{
		assert(!getEntry(name) && "Similar named Resources encountered.");
		passes[name] = t;
	};
	T* getEntry(const String& name)
	{
		typename std::map<String,T*>::iterator t = passes.find(name);
        if(t != passes.end())
		{
			return t->second;
		}
		else
		{
			return 0;
		}	
	};
    PInt getNumEntries()
	{
		return static_cast<PInt>(passes.size());
	};
	///Dumps available info to Log file.
	virtual void dumpInfo() = 0;
	///Dumps entries in the registry to the log file.
	virtual void dumpEntries()
	{
        typename std::map<String,T*>::iterator b = passes.begin();
		typename std::map<String,T*>::iterator e = passes.end();
		while(b!=e)
		{
			ErrorLogger::getLogger()<<b->first<<"\n";			
			++b;
		}

	};

	virtual void removeAllEntries()
	{
        typename std::map<String,T*>::iterator b = passes.begin();
		typename std::map<String,T*>::iterator e = passes.end();
		while(b!=e)
		{
			T* data = b->second;
			delete data;
			++b;
		}
		passes.clear();


	}

	virtual void removeEntry(const String s)//Don't use String& because passes.erase(s) might fail if we delete the Resource holding the String itself
	{
		delete getEntry(s);
		passes.erase(s);
	};
	
	
protected: 
  std::map<String,T*> passes;  
};
}

#endif //__GE_REGISTRY_H__
